package com.markhsiu;

import com.alibaba.AAliServer;
import com.alibaba.BAliServer;
import com.markhsiu.tools.FileUtils;

import java.io.BufferedReader;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Mark Hsiu
 */
public class AppInterAsys {


    public static void main(String[] args) throws Exception {

        getAppInterMap(BAliServer.PATH_APP_INTER);
    }

    public static Map<String,Map<String, Integer>> getAppInterMap(String path) throws Exception{
        Map<String,Map<String, Integer>> appInterMap = new HashMap<>();

        BufferedReader bs = FileUtils.readLines(path);

        int len = 3;
        for (String line = bs.readLine(); line != null; line = bs.readLine()) {
            String[] pair = line.split(",", -1);
            if (pair.length != len) {
                throw new Exception("Invaild solution file");
            }

            String machine1 = pair[0];
            String machine2 = pair[1];
            int limit = Integer.parseInt(pair[2]);
            if(machine1.equals(machine2)){
                limit =+1;
            }
            if(limit > 0){
                continue;
            }

            
            Map<String, Integer> interAppMap = appInterMap.get(machine1);
            if(interAppMap == null){
                interAppMap = new HashMap<>();
                appInterMap.put(machine1, interAppMap);
            }

            interAppMap.put(machine2, limit);
        }


        System.out.println(appInterMap.size());
        return  appInterMap;
    }
}

